package com.edu.imau.IC_CARD;

import com.edu.imau.ManageUserInformation.User;
import com.edu.imau.ManagerSeat.Seat;
import com.edu.imau.ParkingDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ljx
 * @date 2022/12/29 13:14
 */
@WebServlet("/ICadd")
public class ICAddServlet extends HttpServlet {
    private ParkingDao dao = new ParkingDao();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //1 处理参数
        String card_id = request.getParameter("card_id");
        String card_code = request.getParameter("card_code");
        String seat_number = request.getParameter("seat_number");
        String name = request.getParameter("name");
        String gender = request.getParameter("gender");
        String car_number = request.getParameter("car_number");
        String user_addr = request.getParameter("user_addr");
        //2 调用model
        if (card_id == null || card_id.equals("")) {
            IC ic = new IC(-1, card_code, seat_number, name, gender, car_number, user_addr);
            dao.addIC(ic);
            response.sendRedirect("ic.jsp");
        } else {
            IC ic = new IC(Integer.parseInt(card_id), card_code, seat_number, name, gender, car_number, user_addr);
            dao.updateIC(ic);
            response.sendRedirect("icmanager.jsp");
        }
        //3 数据交给View

    }
}
